package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * description:
 *
 * @author:MING
 * @time:2025-02-27-17:05-43
 * @version:
 */
//@ConditionalOnProperty
//@Configuration
////对使用的类进行注册，第2.1种
//@EnableConfigurationProperties(MinioProperties.class)
////通过包名进行扫描
////@ConfigurationPropertiesScan("com.atguigu.lease.common.minio")
//public class MinioConfiguration {
//    //获取映射参数,第一种
////    @Value("${minio.endpoint}")
////    private String endpoint;
//
//    @Autowired
//    private MinioProperties minioProperties;
//
//
//    @Bean
//    public MinioClient minioClient() {
//        return MinioClient.builder().endpoint(minioProperties.getEndpoint()).credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey()).build();
//    }
//}
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(name = "minio.endpoint")
public class MinioConfiguration {

    @Autowired
    private MinioProperties properties;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder().endpoint(properties.getEndpoint()).credentials(properties.getAccessKey(), properties.getSecretKey()).build();
    }
}